
const customRequst = require('../../../common/customRequst');
let app = getApp();
Page({
  data: {
    pay_type: 'alipay',
    isSubmit: false,
    formToken:''
  },
  onLoad: function (options) {
    let that = this
    customRequst.postRequest('api/common/get_form_token', {}).then(res => {
      if (res.code == 1) {
        that.setData({
          formToken: res.data.token
        })
      }
    })
  },

  onShow: function () {
    let that = this
  },

  //切换类型
  checkType:function(e) {
    let type= e.currentTarget.dataset.type;
    this.setData({
      pay_type:type,
    })
  },

  
  formSubmit:function(e){
    let that = this
    if (that.data.isSubmit) {
      wx.showToast({
        title: '请勿重复提交',
        icon: 'none'
      })
      return;
    }
  
    if (!that.data.pay_type) {
      wx.showToast({
        title: '请选择提现方式',
        icon: 'none'
      })
      return;
    }
    let account = e.detail.value.account
    if (!account) {
      wx.showToast({
        title: '账号不能为空',
        icon: 'none'
      })
      return;
    }
    let price = e.detail.value.price
    if (!price) {
      wx.showToast({
        title: '金额不能为空',
        icon: 'none'
      })
      return;
    }else{
      if(price<10){
        wx.showToast({
          title: '金额不能小于10',
          icon: 'none'
        });
        return;
      };
      if(price>5000){
        wx.showToast({
          title: '金额不能超过5000',
          icon: 'none'
        });
        return;
      };
    }
    let remark = e.detail.value.remark


    that.setData({
      isSubmit: true
    })
    customRequst.postRequest('api/groups/profit_withdrawal', {
      token: that.data.formToken,
      pay_type: that.data.pay_type,
      account:account,
      price:price,
      remark: remark,
    }).then(res => {
      if (res.code == 1) {
        wx.showToast({
          title: '提交成功',
          icon: 'success',
          duration: 2000,
          mask:true
        });
        setTimeout(function() {
          wx.navigateTo({
            url: '/pages/promote/promote',
          })
       }, 2000);
      }else {
        wx.showToast({
          title: res.msg,
          mask:true,
          icon:'none',
          success: function () {
            that.setData({
              isSubmit: false,
              Formtoken:res.data.token
            });
          }
        });
      }
    })
  },

})